def is_valid_sequence(sequence):
    stack = []
    brackets_map = {")": "(", "]": "[", "}": "{", ">": "<"}

    for bracket in sequence:
        if bracket in brackets_map.values():
            stack.append(bracket)
        elif bracket in brackets_map:
            if not stack or stack[-1] != brackets_map[bracket]:
                return False
            stack.pop()

    return len(stack) == 0

sequence = input("Введите скобочную последовательность: ")
result = is_valid_sequence(sequence)
print(result)
